#include <iostream>

using namespace std;

struct Node{
	int value;
	Node *next;
};

void reverseList(Node ** head)
{
	Node *curr, *prev, *next;
	curr = *head;
	prev = NULL;
	while (curr){
		next = curr->next;
		curr->next = prev;
		prev = curr;
		curr = next;
	}
	*head = prev;
}

int reverseListTest(){
	int testdata[] = {1,2,3,4,5,6,7,8};
	int size = sizeof(testdata) / sizeof(int);
	Node *head = NULL, *tail = NULL, *ptr;
	for (int i = 0; i < size; i++){
		ptr = new Node;
		ptr->value = testdata[i];
		ptr->next = NULL;
		if (head == NULL)
			head = ptr;
		else 
			tail->next = ptr;

		tail = ptr;
	}

	reverseList( &head );

	ptr = head;
	while (ptr){
		cout <<ptr->value <<" ";
		ptr = ptr->next;
	}
	cout <<endl;
	cin.get();

	return 0;
}